package com.rongke.web.h5controller;

import com.rongke.model.FrontInfor;
import com.rongke.service.FrontInforService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @UserController
 * @Controller
 * @version : Ver 1.0
 */
@Controller
public class NewsController {
	private static final Logger LOGGER = Logger.getLogger(NewsController.class);

	@Autowired
	private FrontInforService frontInforService;

	/**
	 * 单个新闻详情
	 * 
	 * @param newsId
	 * @return
	 */
	@RequestMapping(value = "/news/newsContent.html")
	public ModelAndView viewNewsContent(long newsId) {
		try {
			ModelAndView result = new ModelAndView();

			FrontInfor newsInfo = frontInforService.selectById(newsId);
			if (null == newsInfo) {
				result.setViewName("common/404");
				return result;
			}

			result.addObject("title", newsInfo.getTitle());
			result.addObject("author", newsInfo.getWriter());
			result.addObject("content", newsInfo.getContent());
			result.setViewName("news/news_content");

			return result;
		} catch (Exception e) {
			LOGGER.error("viewNewsContent failed", e);
			throw e;
		}
	}

}
